home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / execd1200.iso / Shareware / Blocks 3 / setup.exe / Source / EDITOR.C < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  18.4 KB  |  872 lines

  1. #include <allegro.h>
  2. #include <jgmod.h>
  3. #include <blocks3.h>
  4.  
  5. int redraw_flag, block_type, mb_flag, level_flag;
  6. int menu_hl, item_hl;
  7. int elev;
  8. int icon_start;
  9. int exit_flag;
  10.  
  11. int f_no;
  12.  
  13. char f[20];
  14.  
  15. void Editor(void)
  16. {
  17.  int mx, my, mb;
  18.  int i, j;
  19.  
  20.  /** Editor Menus **/
  21.  
  22.  menu[0].x = 12;
  23.  menu[0].y = 10;
  24.  menu[0].w = 128;
  25.  menu[0].h = 50;
  26.  menu[0].n = 3;
  27.  
  28.  strcpy(menu[0].item[0].name, "Open        F3");
  29.  strcpy(menu[0].item[1].name, "Save        F2");
  30.  strcpy(menu[0].item[2].name, "Exit     Alt-X");
  31.  menu[1].x = 72;
  32.  menu[1].y = 10;
  33.  menu[1].w = 184;
  34.  menu[1].h = 70;
  35.  menu[1].n = 5;
  36.  
  37.  strcpy(menu[1].item[0].name, "Clear          Ctrl-N");
  38.  strcpy(menu[1].item[1].name, "Clear All            ");
  39.  strcpy(menu[1].item[2].name, "Copy         Ctrl-Ins");
  40.  strcpy(menu[1].item[3].name, "Paste       Shift-Ins");
  41.  strcpy(menu[1].item[4].name, "Arrange              ");
  42.  
  43.  
  44.  menu[2].x = 132;
  45.  menu[2].y = 10;
  46.  menu[2].w = 64;
  47.  menu[2].h = 70;
  48.  menu[2].n = 5;
  49.  
  50.  strcpy(menu[2].item[0].name, "Sunny ");
  51.  strcpy(menu[2].item[1].name, "Castle");
  52.  strcpy(menu[2].item[2].name, "Rocky ");
  53.  strcpy(menu[2].item[3].name, "Snowy ");
  54.  strcpy(menu[2].item[4].name, "Jelly ");
  55.  
  56.  for (j = 0; j < 100; j++)
  57.  {
  58.  for (i = 0; i < 20; i++)
  59.  {
  60.   maps[i][0][0][j] = SOLID;
  61.   maps[i][14][0][j] = SOLID;
  62.   maps[i][0][1][j] = RESERVE;
  63.   maps[i][14][1][j] = RESERVE;
  64.  }
  65.  
  66.  for (i = 0; i < 15; i++)
  67.  {
  68.   maps[0][i][0][j] = SOLID;
  69.   maps[19][i][0][j] = SOLID;
  70.   maps[0][i][1][j] = RESERVE;
  71.   maps[19][i][1][j] = RESERVE;
  72.  }
  73.  }
  74.  
  75.  set_pallete(pallete);
  76.  
  77.  Clear_All();
  78.  
  79.  Maps_to_Map(0);
  80.  
  81.  block_type = BOX;
  82.  level_flag = 0;
  83.  exit_flag = 0;
  84.  
  85.  show_mouse(screen);
  86.  
  87.  scare_mouse();
  88.  Editor_Draw_Screen();
  89.  unscare_mouse();
  90.  
  91.  while (!exit_flag)
  92.  {
  93.   mx = mouse_x;
  94.   my = mouse_y;
  95.   mb = mouse_b;
  96.  
  97.   if ((mb & 1) && (mx > 32) && (my > 32) && (mx < 608) && (my < 448)) Editor_Put_Block(mx/32, my/32, block_type);
  98.   if ((mb & 2) && (mx > 32) && (my > 32) && (mx < 608) && (my < 448)) Editor_Put_Block(mx/32, my/32, 0);
  99.  
  100.   if ((mb & 1) && (my > 448)) Editor_Change_Block_Type(mx/32);
  101.  
  102.   if (my < 10) Highlight_Menu(mx);
  103.   else
  104.   if (menu_hl != -1)
  105.   {
  106.    Editor_Draw_Menu();
  107.    blit(temp, screen, 0, 0, 0, 0, 232, 10);
  108.    menu_hl = -1;
  109.   }
  110.  
  111.   if (key[KEY_TAB])
  112.   {
  113.    level_flag = 1 - level_flag;
  114.    while(key[KEY_TAB]);
  115.  
  116.    scare_mouse();
  117.    if (level_flag) textprintf(screen, font, 480, 2, 0, "Top   ");
  118.    else textprintf(screen, font, 480, 2, 0, "Bottom");
  119.    unscare_mouse();
  120.   }
  121.  
  122.   if ((key[KEY_F9]) || ((mb & 1) && (menu_hl == 3)))
  123.   {
  124.    Map_to_Maps(elev);
  125.  
  126.    game_type = EDITOR_GAME;
  127.    lev = elev;
  128.  
  129.    scare_mouse();
  130.    Run_Level();
  131.    fade_in(pallete, 10);
  132.    unscare_mouse();
  133.  
  134.    Maps_to_Map(elev);
  135.    redraw_flag = 1;
  136.   }
  137.  
  138.   if ((menu_hl != -1) && (mb & 1)) Drop_Down();
  139.  
  140.   if (key[KEY_MINUS_PAD])
  141.   {
  142.    Map_to_Maps(elev);
  143.  
  144.    elev--;
  145.    if (elev == -1) elev = 99;
  146.  
  147.    Maps_to_Map(elev);
  148.  
  149.    Editor_Draw_Menu();
  150.    blit(temp, screen, 0, 0, 0, 0, 639, 10);
  151.  
  152.    while (key[KEY_MINUS_PAD]);
  153.    redraw_flag = 1;
  154.   }
  155.  
  156.   if (key[KEY_PLUS_PAD])
  157.   {
  158.    Map_to_Maps(elev);
  159.  
  160.    elev++;
  161.    if (elev == 100) elev = 0;
  162.  
  163.    Maps_to_Map(elev);
  164.  
  165.    Editor_Draw_Menu();
  166.    blit(temp, screen, 0, 0, 0, 0, 639, 10);
  167.  
  168.    while (key[KEY_PLUS_PAD]);
  169.    redraw_flag = 1;
  170.   }
  171.  
  172.   if (key[KEY_PGUP])
  173.   {
  174.    Map_to_Maps(elev);
  175.  
  176.    elev+=10;
  177.    if (elev > 99) elev -= 100;
  178.  
  179.    Maps_to_Map(elev);
  180.  
  181.    Editor_Draw_Menu();
  182.    blit(temp, screen, 0, 0, 0, 0, 639, 10);
  183.  
  184.    while (key[KEY_PGUP]);
  185.    redraw_flag = 1;
  186.   }
  187.  
  188.   if (key[KEY_PGDN])
  189.   {
  190.    Map_to_Maps(elev);
  191.  
  192.    elev-=10;
  193.    if (elev < 0) elev += 100;
  194.  
  195.    Maps_to_Map(elev);
  196.  
  197.    Editor_Draw_Menu();
  198.    blit(temp, screen, 0, 0, 0, 0, 639, 10);
  199.  
  200.    while (key[KEY_PGDN]);
  201.    redraw_flag = 1;
  202.   }
  203.  
  204.   if (((key[KEY_CONTROL]) || (key[KEY_RCONTROL])) && (key[KEY_INSERT]))
  205.   {
  206.    Map_to_Maps(elev);
  207.    Copy_To_Buffer(elev);
  208.    redraw_flag = 1;
  209.    while(key[KEY_INSERT]);
  210.   }
  211.  
  212.   if (((key[KEY_LSHIFT]) || (key[KEY_RSHIFT])) && (key[KEY_INSERT]))
  213.   {
  214.    Copy_From_Buffer(elev);
  215.    Maps_to_Map(elev);
  216.    redraw_flag = 1;
  217.    while(key[KEY_INSERT]);
  218.   }
  219.  
  220.   if ((key[KEY_RIGHT]) && (icon_start < 20))
  221.   {
  222.    icon_start++;
  223.    Editor_Draw_Tiles();
  224.    scare_mouse();
  225.    blit(temp, screen, 0, 448, 0, 448, 640, 32);
  226.    unscare_mouse();
  227.    while (key[KEY_RIGHT]);
  228.   }
  229.  
  230.   if ((key[KEY_LEFT]) && (icon_start > 0))
  231.   {
  232.    icon_start--;
  233.    Editor_Draw_Tiles();
  234.    scare_mouse();
  235.    blit(temp, screen, 0, 448, 0, 448, 640, 32);
  236.    unscare_mouse();
  237.    while (key[KEY_LEFT]);
  238.   }
  239.  
  240.   if (redraw_flag)
  241.   {
  242.    Editor_Draw_Screen();
  243.    redraw_flag = 0;
  244.   }
  245.  
  246.   if (key[KEY_F2])
  247.   {
  248.    while (key[KEY_F2]);
  249.    Save_Maps();
  250.  
  251.    redraw_flag = 1;
  252.   }
  253.  
  254.   if (key[KEY_F3])
  255.   {
  256.    while (key[KEY_F3]);
  257.    Open_Maps();
  258.  
  259.    redraw_flag = 1;
  260.   }
  261.  
  262.   if ((mx > 32) && (my > 32) && (mx < 608) && (my < 448)) Editor_Key_Put_Tile(mx/32, my/32);
  263.  
  264.   if (mb & 1) mb_flag = 1;
  265.   else mb_flag = 0;
  266.  }
  267.  
  268.  blit(screen, temp, 0, 0, 0, 0, 640, 480);
  269.  
  270.  Transition_Out(temp, pallete);
  271. }
  272.  
  273. void Editor_Draw_Screen(void)
  274. {
  275.  Change_Motif(map_motif[elev]);
  276.  
  277.  blit(back, temp, 0, 0, 0, 0, 640, 480);
  278.  Draw_Map();
  279.  
  280.  Editor_Draw_Menu();
  281.  Editor_Draw_Tiles();
  282.  
  283.  scare_mouse();
  284.  blit(temp, screen, 0, 0, 0, 0, 640, 480);
  285.  unscare_mouse();
  286. }
  287.  
  288. void Editor_Draw_Menu(void)
  289. {
  290.  rectfill(temp, 0, 0, 639, 12, 7);
  291.  rect(temp, 0, 0, 639, 12, 0);
  292.  
  293.  text_mode(7);
  294.  
  295.  textprintf(temp, font, 12, 2, 0, " File ");
  296.  textprintf(temp, font, 72, 2, 0, " Edit ");
  297.  textprintf(temp, font, 132, 2, 0, " Motif ");
  298.  textprintf(temp, font, 192, 2, 0, " Run ");
  299.  
  300.  if (level_flag) textprintf(temp, font, 480, 2, 0, "Top   ");
  301.  else textprintf(temp, font, 480, 2, 0, "Bottom");
  302.  
  303.  textprintf(temp, font, 560, 2, 0, "Level: %d ", elev);
  304.  
  305. }
  306.  
  307. void Editor_Put_Block(int x, int y, int b)
  308. {
  309.  if (map[x][y][level_flag] != b)
  310.  {
  311.   map[x][y][level_flag] = b;
  312.   redraw_flag = 1;
  313.  }
  314. }
  315.  
  316. void Highlight_Menu(int x)
  317. {
  318.  int old_menu_hl;
  319.  
  320.  old_menu_hl = menu_hl;
  321.  
  322.  text_mode(7);
  323.  
  324.  textprintf(temp, font, 12, 2, 0, " File ");
  325.  textprintf(temp, font, 72, 2, 0, " Edit ");
  326.  textprintf(temp, font, 132, 2, 0, " Motif ");
  327.  textprintf(temp, font, 192, 2, 0, " Run ");
  328.  
  329.  text_mode(makecol(180, 180, 255));
  330.  
  331.  if ((x > 20) && ( x < 52) && (menu_hl != 0))
  332.  {
  333.   textprintf(temp, font, 12, 2, 0, " File ");
  334.   menu_hl = 0;
  335.  }
  336.  if ((x > 80) && ( x < 112) && (menu_hl != 1))
  337.  {
  338.   textprintf(temp, font, 72, 2, 0, " Edit ");
  339.   menu_hl = 1;
  340.  }
  341.  if ((x > 140) && ( x < 180) && (menu_hl != 2))
  342.  {
  343.   textprintf(temp, font, 132, 2, 0, " Motif ");
  344.   menu_hl = 2;
  345.  }
  346.  if ((x > 200) && ( x < 224) && (menu_hl != 3))
  347.  {
  348.   textprintf(temp, font, 192, 2, 0, " Run ");
  349.   menu_hl = 3;
  350.  }
  351.  
  352.  if (old_menu_hl == menu_hl) return;
  353.  
  354.  scare_mouse();
  355.  blit(temp, screen, 0, 0, 0, 0, 232, 10);
  356.  unscare_mouse();
  357. }
  358.  
  359. void Draw_Drop_Down(int item)
  360. {
  361.  int i;
  362.  
  363.  rectfill(temp, menu[menu_hl].x, menu[menu_hl].y,
  364.           menu[menu_hl].x + menu[menu_hl].w,
  365.           menu[menu_hl].y + menu[menu_hl].h, 7);
  366.  
  367.  rect(temp, menu[menu_hl].x, menu[menu_hl].y,
  368.           menu[menu_hl].x + menu[menu_hl].w - 1,
  369.           menu[menu_hl].y + menu[menu_hl].h - 1, 0);
  370.  
  371.  text_mode(7);
  372.  
  373.  for (i = 0; i < menu[menu_hl].n; i++)
  374.  textprintf(temp, font, menu[menu_hl].x + 8, menu[menu_hl].y + 10 + i*10, 0, "%s", menu[menu_hl].item[i].name);
  375.  
  376.  if ((item > -1) && (item < menu[menu_hl].n))
  377.  {
  378.   text_mode(makecol(180, 180, 255));
  379.   textprintf(temp, font, menu[menu_hl].x + 8, menu[menu_hl].y + 10 + item*10, 0, "%s", menu[menu_hl].item[item].name);
  380.  }
  381.  
  382.  scare_mouse();
  383.  
  384.  blit(temp, screen, menu[menu_hl].x, menu[menu_hl].y,
  385.           menu[menu_hl].x, menu[menu_hl].y,
  386.           menu[menu_hl].w, menu[menu_hl].h);
  387.  
  388.  unscare_mouse();
  389. }
  390.  
  391. void Drop_Down(void)
  392. {
  393.  int old_item_hl;
  394.  
  395.  old_item_hl = -1;
  396.  
  397.  while (mouse_b);
  398.  
  399.  while ((!(mouse_b & 1)) && (mouse_x > menu[menu_hl].x)
  400.     && (mouse_x < menu[menu_hl].x + menu[menu_hl].w)
  401.     && (mouse_y < menu[menu_hl].y + menu[menu_hl].h))
  402.  {
  403.   old_item_hl = item_hl;
  404.  
  405.   item_hl = (mouse_y - menu[menu_hl].y - 10)/10;
  406.  
  407.   if (item_hl != old_item_hl) Draw_Drop_Down(item_hl);
  408.  }
  409.  
  410.  redraw_flag = 1;
  411.  
  412.  if (!(mouse_b & 1)) return;
  413.  
  414.  while (mouse_b);
  415.  
  416.  if (menu_hl == 0)
  417.  {
  418.   if (item_hl == 2) exit_flag = 1;
  419.   if (item_hl == 0) Open_Maps(13);
  420.   if (item_hl == 1) Save_Maps(13);
  421.  }
  422.  if (menu_hl == 1)
  423.  {
  424.   if (item_hl == 0) Clear(elev);
  425.   if (item_hl == 1) Clear_All();
  426.  
  427.   if (item_hl == 2)
  428.   {
  429.    Map_to_Maps(elev);
  430.    Copy_To_Buffer(elev);
  431.   }
  432.  
  433.   if (item_hl == 3)
  434.   {
  435.    Copy_From_Buffer(elev);
  436.    Maps_to_Map(elev);
  437.   }
  438.  }
  439.  if (menu_hl == 2)
  440.  {
  441.   if (item_hl == 0) Change_Motif(SUNNY);
  442.   if (item_hl == 1) Change_Motif(CASTLE);
  443.   if (item_hl == 2) Change_Motif(ROCKY);
  444.   if (item_hl == 3) Change_Motif(SNOWY);
  445.   map_motif[elev] = motif;
  446.  }
  447. }
  448.  
  449. void Remember_File(char *fn, int a, int b)
  450. {
  451.  strcpy(dir[f_no].name, get_filename(fn));
  452.  f_no++;
  453. }
  454.  
  455. void Directory(void)
  456. {
  457.  int j;
  458.  
  459.  rectfill(temp, 0, 12, 640, 480, 7);
  460.  rectfill(temp, 0, 0, 640, 12, makecol(180, 180, 255));
  461.  line(temp, 0, 12, 640, 12, 0);
  462.  line(temp, 128, 12, 128, 468, 0);
  463.  line(temp, 256, 12, 256, 468, 0);
  464.  line(temp, 384, 12, 384, 468, 0);
  465.  line(temp, 512, 12, 512, 468, 0);
  466.  line(temp, 0, 468, 640, 468, 0);
  467.  
  468.  f_no = 0;
  469.  for_each_file("./maps/*.map", NULL, Remember_File, 0);
  470.  
  471.  text_mode(7);
  472.  for (j = 0; j < f_no; j++)
  473.  textprintf(temp, font, j/37*128 + 10, (j % 37) * 12 + 20, 0, "%s", dir[j].name);
  474. }
  475.  
  476. int Yes_Or_No(void)
  477. {
  478.  int m, mx, my;
  479.  
  480.  while (mouse_b & 1);
  481.  m = -1;
  482.  
  483.  while ((!(mouse_b & 1)) && (!key[KEY_ESC])
  484.        && (!key[KEY_Y]) && (!key[KEY_N]))
  485.  {
  486.   mx = mouse_x;
  487.   my = mouse_y;
  488.   if ((my > 130) && (my < 140))
  489.   {
  490.    if ((mx > 276) && (mx < 300) && (m != 1))
  491.    {
  492.     m = 1;
  493.     scare_mouse();
  494.     text_mode(7);
  495.     textprintf(screen, font, 268, 130, 0, " YES      NO ");
  496.     text_mode(makecol(180, 180, 255));
  497.     textprintf(screen, font, 268, 130, 0, " YES ");
  498.     unscare_mouse();
  499.    }
  500.    if ((mx > 348) && (mx < 364) && (m != 2))
  501.    {
  502.     m = 2;
  503.     scare_mouse();
  504.     text_mode(7);
  505.     textprintf(screen, font, 268, 130, 0, " YES      NO ");
  506.     text_mode(makecol(180, 180, 255));
  507.     textprintf(screen, font, 340, 130, 0, " NO ");
  508.     unscare_mouse();
  509.    }
  510.   }
  511.  }
  512.  
  513.  if (((m == 1) && (mouse_b & 1)) || (key[KEY_Y])) return 1;
  514.  
  515.  return 0;
  516. }
  517.  
  518. void Open_Maps(void)
  519. {
  520.  int mx, my;
  521.  int file_sel = 0;
  522.  char fn[20];
  523.  int i, j, k, l;
  524.  PACKFILE *file;
  525.  
  526.  Directory();
  527.  
  528.  text_mode(-1);
  529.  textprintf_centre(temp, font, 320, 2, 0, "Open File...");
  530.  
  531.  scare_mouse();
  532.  blit(temp, screen, 0, 0, 0, 0, 640, 480);
  533.  unscare_mouse();
  534.  
  535.  while ((!mouse_b & 1) && (!key[KEY_ESC]))
  536.  {
  537.   mx = mouse_x;
  538.   my = mouse_y;
  539.  
  540.   if ((file_sel != mx/128 * 37 + (my-20)/12) && (my > 12) && (my < 460)
  541.   && (mx/128 * 37 + (my-20)/12 < f_no))
  542.   {
  543.    text_mode(7);
  544.    scare_mouse();
  545.    textprintf(screen, font, file_sel/37*128 + 10, (file_sel % 37) * 12 + 20, 0, "%s", dir[file_sel].name);
  546.    file_sel = mx/128 * 37 + (my-20)/12;
  547.    text_mode(makecol(180, 180, 255));
  548.    textprintf(screen, font, file_sel/37*128 + 10, (file_sel % 37) * 12 + 20, 0, "%s", dir[file_sel].name);
  549.    unscare_mouse();
  550.   }
  551.  }
  552.  
  553.  if (key[KEY_ESC]) return;
  554.  
  555.  /** Load File **/
  556.  
  557.  rectfill(screen, 192, 90, 448, 140, 7);
  558.  rect(screen, 192, 90, 448, 140, 0);
  559.  
  560.  text_mode(7);
  561.  
  562.  scare_mouse();
  563.  textprintf_centre(screen, font, 320, 100, 0, "WARNING: Loading file will");
  564.  textprintf_centre(screen, font, 320, 110, 0, "delete unsaved maps. Continue?");
  565.  textprintf(screen, font, 276, 130, 0, "YES      NO");
  566.  unscare_mouse();
  567.  
  568.  if (Yes_Or_No() == 0) return;
  569.  
  570.  strcpy(fn, "./maps/");
  571.  strcat(fn, dir[file_sel].name);
  572.  
  573.  file = pack_fopen(fn, "rp");
  574.  
  575.  for (l = 0; l < 100; l++)
  576.  for (k = 0; k < 2; k++)
  577.  for (j = 0; j < 15; j++)
  578.  for (i = 0; i < 20; i++)
  579.  maps[i][j][k][l] = pack_igetw(file);
  580.  
  581.  for (l = 0; l < 100; l++)
  582.  map_motif[l] = pack_igetw(file);
  583.  
  584.  pack_fclose(file);
  585.  
  586.  elev = 0;
  587.  Maps_to_Map(0);
  588.  
  589.  while(mouse_b & 1);
  590. }
  591.  
  592. void Save_Maps(void)
  593. {
  594.  int file_sel = 0;
  595.  char fn[20];
  596.  int i, j, k, l, mx, my;
  597.  PACKFILE *file;
  598.  
  599.  Directory();
  600.  
  601.  text_mode(makecol(180, 180, 255));
  602.  textprintf_centre(temp, font, 320, 2, 0, "Save Maps...");
  603.  
  604.  text_mode(7);
  605.  textprintf(temp, font, 10, 470, 0, "Filename:");
  606.  
  607.  k = 0;
  608.  
  609.  clear_keybuf();
  610.  
  611.  scare_mouse();
  612.  blit(temp, screen, 0, 0, 0, 0, 640, 480);
  613.  unscare_mouse();
  614.  
  615.  while (!(mouse_b & 1) && (!key[KEY_ESC]) && (!key[KEY_ENTER]))
  616.  {
  617.   mx = mouse_x;
  618.   my = mouse_y;
  619.  
  620.   if ((file_sel != mx/128 * 37 + (my-20)/12) && (my > 12) && (my < 460)
  621.   && (mx/128 * 37 + (my-20)/12 < f_no))
  622.   {
  623.    text_mode(7);
  624.    scare_mouse();
  625.    textprintf(screen, font, file_sel/37*128 + 10, (file_sel % 37) * 12 + 20, 0, "%s", dir[file_sel].name);
  626.    file_sel = mx/128 * 37 + (my-20)/12;
  627.  text_mode(makecol(180, 180, 255));
  628.    textprintf(screen, font, file_sel/37*128 + 10, (file_sel % 37) * 12 + 20, 0, "%s", dir[file_sel].name);
  629.    unscare_mouse();
  630.   }
  631.   if (keypressed())
  632.   {
  633.    j = readkey();
  634.    if (j >> 8 == KEY_BACKSPACE)
  635.    {
  636.     if (k > 0)
  637.     {
  638.      k--;
  639.      text_mode(7);
  640.      textprintf(screen, font, 85 + k*8, 470, 0, "  ");
  641.     }
  642.    }
  643.    else
  644.    {
  645.     if (k == 8) k = 7;
  646.     text_mode(7);
  647.     textprintf(screen, font, 85 + k*8, 470, 0, " ");
  648.     textprintf(screen, font, 85 + k*8, 470, 0, "%c", j & 0xff);
  649.     f[k] = j & 0xff;
  650.     k++;
  651.    }
  652.   }
  653.  }
  654.  
  655.  if ((key[KEY_ENTER]) && (k > 0))
  656.  {
  657.   f[k - 1] = 46;
  658.   f[k] = 109;
  659.   f[k + 1] = 97;
  660.   f[k + 2] = 112;
  661.   f[k + 3] = NULL;
  662.  }
  663.  
  664.  if (key[KEY_ESC])
  665.  {
  666.   scare_mouse();
  667.   blit(temp, screen, 0, 0, 0, 0, 640, 480);
  668.   unscare_mouse();
  669.   return;
  670.  }
  671.  
  672.  /** Save File **/
  673.  
  674.  if (mouse_b & 1) strcpy(f, dir[file_sel].name);
  675.  
  676.  strcpy(fn, "./maps/");
  677.  strcat(fn, f);
  678.  
  679.  if (exists(fn))
  680.  {
  681.   rectfill(screen, 220, 90, 420, 140, 7);
  682.   rect(screen, 220, 90, 420, 140, 0);
  683.  
  684.   text_mode(7);
  685.  
  686.   scare_mouse();
  687.   textprintf_centre(screen, font, 320, 100, 0, "Are you sure you want");
  688.   textprintf_centre(screen, font, 320, 110, 0, "to overwrite this file?");
  689.   textprintf(screen, font, 276, 130, 0, "YES      NO");
  690.   unscare_mouse();
  691.  
  692.   if (Yes_Or_No() == 0) return;
  693.  
  694.   delete_file(fn);
  695.  }
  696.  
  697.  Map_to_Maps(elev);
  698.  
  699.  file = pack_fopen(fn, "wp");
  700.  
  701.  for (l = 0; l < 100; l++)
  702.  for (k = 0; k < 2; k++)
  703.  for (j = 0; j < 15; j++)
  704.  for (i = 0; i < 20; i++)
  705.  pack_iputw(maps[i][j][k][l], file);
  706.  
  707.  for (l = 0; l < 100; l++)
  708.  pack_iputw(map_motif[l], file);
  709.  
  710.  pack_fclose(file);
  711.  
  712.  while(mouse_b & 1);
  713.  while(key[KEY_ENTER]);
  714. }
  715.  
  716. void Map_to_Maps(int lev)
  717. {
  718.  int i, j, k;
  719.  
  720.  for (k = 0; k < 2; k++)
  721.  for (j = 0; j < 15; j++)
  722.  for (i = 0; i < 20; i++)
  723.  maps[i][j][k][lev] = map[i][j][k];
  724. }
  725.  
  726. void Maps_to_Map(int lev)
  727. {
  728.  int i, j, k;
  729.  
  730.  for (k = 0; k < 2; k++)
  731.  for (j = 0; j < 15; j++)
  732.  for (i = 0; i < 20; i++)
  733.  map[i][j][k] = maps[i][j][k][lev];
  734. }
  735.  
  736. void Copy_To_Buffer(int lev)
  737. {
  738.  int i, j, k;
  739.  
  740.  for (k = 0; k < 2; k++)
  741.  for (j = 0; j < 15; j++)
  742.  for (i = 0; i < 20; i++)
  743.  maps[i][j][k][100] = maps[i][j][k][lev];
  744. }
  745.  
  746. void Copy_From_Buffer(int lev)
  747. {
  748.  int i, j, k;
  749.  
  750.  for (k = 0; k < 2; k++)
  751.  for (j = 0; j < 15; j++)
  752.  for (i = 0; i < 20; i++)
  753.  maps[i][j][k][lev] = maps[i][j][k][100];
  754. }
  755.  
  756. void Editor_Draw_Tiles(void)
  757. {
  758.  blit(editor_icons, temp, icon_start*32, 0, 0, 448, 640, 32);
  759. }
  760.  
  761. void Editor_Change_Block_Type(int b)
  762. {
  763.  b = b + icon_start;
  764.  
  765.  if (b == 0) block_type = SOLID;
  766.  if (b == 1) block_type = BOX;
  767.  if (b == 2) block_type = AUDREY;
  768.  if (b == 3) block_type = AN;
  769.  if (b == 4) block_type = TOKEN;
  770.  
  771.  if (b == 5) block_type = RED_TELEPORT;
  772.  if (b == 6) block_type = BLUE_TELEPORT;
  773.  if (b == 7) block_type = GREEN_TELEPORT;
  774.  
  775.  if (b == 8) block_type = LASER_UP;
  776.  if (b == 9) block_type = LASER_RIGHT;
  777.  if (b == 10) block_type = LASER_DOWN;
  778.  if (b == 11) block_type = LASER_LEFT;
  779.  if (b == 12) block_type = LASER_4WAY;
  780.  
  781.  if (b == 13) block_type = MIRROR_MINUS;
  782.  if (b == 14) block_type = MIRROR_PLUS;
  783.  
  784.  if (b == 15) block_type = BOMB1;
  785.  if (b == 16) block_type = BOMB2;
  786.  if (b == 17) block_type = BOMB3;
  787.  
  788.  if (b == 18) block_type = MON0;
  789.  if (b == 19) block_type = MON1;
  790.  if (b == 20) block_type = LASER_FILTER;
  791.  
  792.  if (b == 21) block_type = RED_SWITCH;
  793.  if (b == 22) block_type = GREEN_SWITCH;
  794.  if (b == 23) block_type = BLUE_SWITCH;
  795.  
  796.  if (b == 24) block_type = RED_DOOR_CLOSE;
  797.  if (b == 25) block_type = GREEN_DOOR_CLOSE;
  798.  if (b == 26) block_type = BLUE_DOOR_CLOSE;
  799.  
  800.  if (b == 27) block_type = FALL;
  801. }
  802.  
  803. void Clear(int l)
  804. {
  805.  int i, j, k;
  806.  
  807.  for (k = 0; k < 2; k++)
  808.  for (i = 1; i < 19; i++)
  809.  for (j = 1; j < 14; j++)
  810.  maps[i][j][k][l] = 0;
  811.  
  812.  Maps_to_Map(l);
  813. }
  814.  
  815. void Clear_All(void)
  816. {
  817.  int i;
  818.  
  819.  for (i = 0; i < 100; i++)
  820.  Clear(i);
  821.  
  822.  Reset_Motifs();
  823.  
  824.  Maps_to_Map(elev);
  825. }
  826.  
  827. void Editor_Key_Put_Tile(int mx, int my)
  828. {
  829.  if (key[KEY_1]) Editor_Put_Block(mx, my, SOLID);
  830.  if (key[KEY_2]) Editor_Put_Block(mx, my, BOX);
  831.  if (key[KEY_3]) Editor_Put_Block(mx, my, TOKEN);
  832.  if (key[KEY_4]) Editor_Put_Block(mx, my, FALL);
  833.  if (key[KEY_5]) Editor_Put_Block(mx, my, BOMB1);
  834.  if (key[KEY_6]) Editor_Put_Block(mx, my, BOMB2);
  835.  if (key[KEY_7]) Editor_Put_Block(mx, my, BOMB3);
  836.  if (key[KEY_8]) Editor_Put_Block(mx, my, AN);
  837.  if (key[KEY_9]) Editor_Put_Block(mx, my, AUDREY);
  838.  
  839.  if (key[KEY_Q]) Editor_Put_Block(mx, my, RED_SWITCH);
  840.  if (key[KEY_W]) Editor_Put_Block(mx, my, GREEN_SWITCH);
  841.  if (key[KEY_E]) Editor_Put_Block(mx, my, BLUE_SWITCH);
  842.  if (key[KEY_A]) Editor_Put_Block(mx, my, RED_DOOR_CLOSE);
  843.  if (key[KEY_S]) Editor_Put_Block(mx, my, GREEN_DOOR_CLOSE);
  844.  if (key[KEY_D]) Editor_Put_Block(mx, my, BLUE_DOOR_CLOSE);
  845.  
  846.  if (key[KEY_I]) Editor_Put_Block(mx, my, LASER_UP);
  847.  if (key[KEY_J]) Editor_Put_Block(mx, my, LASER_LEFT);
  848.  if (key[KEY_M]) Editor_Put_Block(mx, my, LASER_DOWN);
  849.  if (key[KEY_L]) Editor_Put_Block(mx, my, LASER_RIGHT);
  850.  if (key[KEY_K]) Editor_Put_Block(mx, my, LASER_4WAY);
  851.  
  852.  if (key[KEY_F]) Editor_Put_Block(mx, my, LASER_FILTER);
  853.  
  854.  if (key[KEY_Z]) Editor_Put_Block(mx, my, RED_TELEPORT);
  855.  if (key[KEY_C]) Editor_Put_Block(mx, my, GREEN_TELEPORT);
  856.  if (key[KEY_X]) Editor_Put_Block(mx, my, BLUE_TELEPORT);
  857.  
  858.  if (key[KEY_SLASH]) Editor_Put_Block(mx, my, MIRROR_PLUS);
  859.  if (key[KEY_BACKSLASH]) Editor_Put_Block(mx, my, MIRROR_MINUS);
  860.  
  861.  if (key[KEY_BACKSPACE]) Editor_Put_Block(mx, my, 0);
  862.  if (key[KEY_DEL]) Editor_Put_Block(mx, my, 0);
  863. }
  864.  
  865. void Reset_Motifs(void)
  866. {
  867.  int i;
  868.  
  869.  for (i = 0; i < 100; i++)
  870.  map_motif[i] = SUNNY;
  871. }
  872.